package com.hyc.myvideo.ui.fragment.homefargment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import com.flyco.tablayout.SlidingTabLayout;
import com.hyc.myvideo.R;
import com.hyc.myvideo.ui.activity.home.AudioActivity;
import com.hyc.myvideo.ui.activity.home.VideoActivity;
import com.hyc.myvideo.ui.base.BaseFragment;
import com.hyc.myvideo.ui.fragment.column.CourseFragment;
import com.hyc.myvideo.ui.fragment.column.TeacherFragment;
import java.util.ArrayList;
import java.util.List;

/**
 * 专栏
 *
 * @author gyb
 * @version 1.0
 * @created 2017/06/16
 */
public class ColumnFragment extends BaseFragment {

  private final String[] mTitles = { "名师/机构", "课程" };
  @BindView(R.id.head_center_title) TextView mCenterTitle;//标题
  @BindView(R.id.head_right_img) ImageView mRightImg;
  private List<BaseFragment> fragments = new ArrayList<>();

  @BindView(R.id.fragment_column_stl_s) SlidingTabLayout mTable;

  @BindView(R.id.fragment_column_vp_s) ViewPager mPager;
  private MyPagerAdapter mAdapter;

  @Override protected int getLayoutId() {
    return R.layout.fragment_column;
  }

  protected void initView() {
    mCenterTitle.setText("专栏");
    mCenterTitle.setVisibility(View.VISIBLE);
    mRightImg.setImageResource(R.mipmap.home_practice);
    mRightImg.setVisibility(View.VISIBLE);
    fragments.add(new TeacherFragment());
    fragments.add(new CourseFragment());
    mAdapter = new MyPagerAdapter(getFragmentManager());
    mPager.setAdapter(mAdapter);
    mTable.setViewPager(mPager);
  }

  @Override protected void initData() {

  }

  @Override protected void onNexts(String result, String method) {

  }

  @Override protected void onError() {

  }

  @OnClick(R.id.head_right_img) public void onViewClicked() {
    startActivity(new Intent(getActivity(), AudioActivity.class));
  }

  private class MyPagerAdapter extends FragmentPagerAdapter {

    public MyPagerAdapter(FragmentManager fm) {
      super(fm);
    }

    @Override public Fragment getItem(int position) {
      return fragments.get(position);
    }

    @Override public int getCount() {
      return mTitles.length;
    }

    @Override public CharSequence getPageTitle(int position) {
      return mTitles[position];
    }
  }
}
